package com.jsnkj.basic.activity

import androidx.lifecycle.MutableLiveData
import com.jsnkj.basic.bean.EarningsBean
import com.jsnkj.basic.bean.ErrorEntity
import com.jsnkj.basic.bean.InviteCodeEntity
import com.jsnkj.basic.bean.UserEarningsEntity
import com.jsnkj.basic.http.HttpApiService
import com.jsnkj.basic.mvvm.HttpViewModel
import com.jsnkj.basic.util.SharePreferencesUtil
import com.yang.http.HttpRequest

class InviteFriendsViewModel : HttpViewModel() {

    //奖励任务列表
    var rewardTaskList = ArrayList<EarningsBean.BToARatiosBean>()

    fun initRewardTaskList() {
        rewardTaskList = ArrayList()
        SharePreferencesUtil.getInstance().getSettingEntity().earnings?.b_to_a_ratios?.let {
            for (bean in it) {
                //过滤数据
                if ("=" == bean.condition) {
                    rewardTaskList.add(bean)
                }
            }
        }
    }



    var postHttpResult: MutableLiveData<InviteCodeEntity> = MutableLiveData()

    var errorResult: MutableLiveData<ErrorEntity> = MutableLiveData()

    /**
     * 获取用户分享地址
     */
    fun postUserInviteCode() {
        launchHttp({
            HttpRequest.getService(HttpApiService::class.java).postUserInviteCode()
        }, onResult = { it ->
            com.jsnkj.basic.util.LogUtils.e("请求成功：$it")
            postHttpResult.value = it
        }, onFailed = { code, msg ->
            errorResult.value = ErrorEntity.getInstance(code,msg)
        }) {
        }
    }


    var postUserEarningsResult: MutableLiveData<UserEarningsEntity> = MutableLiveData()

    /**
     * 获取用户佣金
     */
    fun postUserEarnings() {
        launchHttp({
            HttpRequest.getService(HttpApiService::class.java).postUserEarnings()
        }, onResult = { it ->
            com.jsnkj.basic.util.LogUtils.e("获取用户佣金 请求成功：$it")
            postUserEarningsResult.value = it
        }, onFailed = { code, msg ->
            errorResult.value =ErrorEntity.getInstance(code,msg)
        }) {
        }
    }
}